package com.natasa.monitor.service;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * 数据解析器工厂类
 * @author jianfeihit
 *
 */
@Component(value="parserFactory")
public class ParserFactory implements ApplicationContextAware {
    private ApplicationContext context;

    public IParser getParser(String parserName) {
        if (context == null) {
            return null;
        } else {
            return (IParser) context.getBean(parserName);
        }
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;
    }
}
